var config = require('../../config');
var common = require('../utils/common.js');
var promise = require('../utils/es6-promise.auto.min.js');
var util=require('../utils/util.js');
function load_page(data,tab_page, username, page) {
  wx.request({
    url: config.materials +'/search/findByTagNameAndFavorerUsername',
    data: {
      tagName: config.tagName,
      username: username,
      page:data.page,
      size:data.size
    },
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var data = res.data;
      var materials = data._embedded.materials;
      var obj={};
      obj.count=0;
      var len=materials.length;
      new promise(function (resolve, reject) {
       
        for (var i = 0; i < materials.length;i++){
          materials[i].bindtap = 'inplay_material_p';
          materials[i].showTime = util.formateDate(materials[i].showTime);
          materials[i].day = util.getDays(materials[i].showTime);
          materials[i].checked=false;
        }
        resolve(materials);
      }).then(function (materials){
        var list = tab_page.list;
        if (list == null || undefined == list) {
          tab_page.list = materials;
          tab_page.page = data.page;
          tab_page.pageSize = data.page.totalPages;
        } else {
          tab_page.list = list.contact(materials);
          tab_page.page = data.page;
        }
        page.setData({
          list: tab_page.list
        });
      });

      
    }
  });
}

module.exports = {
  load_page: load_page
}